﻿using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Menu;
using Application = Autodesk.Revit.ApplicationServices.Application;
using xXYZ = Autodesk.Revit.DB.XYZ;

namespace RevitAddin
{
    [TransactionAttribute(TransactionMode.Manual)]
    [RegenerationAttribute(RegenerationOption.Manual)]
    public class WidthCodeCMD : IExternalEventHandler
    {
    
        public Action<List<xXYZ>> action { get; set; }
       

        public void Execute(UIApplication app)
        {
            UIDocument uidoc = app.ActiveUIDocument;
            Document doc = uidoc.Document;
            Application revitApp = app.Application;
    
            try
            {
                List<xXYZ> xyzList = new List<xXYZ>();
                Reference referer = uidoc.Selection.PickObject(ObjectType.Edge, "请选择主干道电缆沟宽度边线");
                Element elem = doc.GetElement(referer);
                Edge edge = elem.GetGeometryObjectFromReference(referer) as Edge;
                Curve curve = edge.AsCurve() as Curve;
                xyzList.Add(curve.Evaluate(0, true));        
                xyzList.Add(curve.Evaluate(1, true));
             
                    action?.Invoke(xyzList);
                
            }
            catch (Exception)
            {
               
            }
        }

        public string GetName()
        {
            return "WidthCCodeCMD";
        }
    }
  
}
